/**
 *
 */
package kevin.study.zephyr.internal;

import java.util.Observable;
import java.util.Observer;

import kevin.study.zephyr.domain.dao.IGenericDAO;
import kevin.study.zephyr.domain.factory.DocumentFactory;
import kevin.study.zephyr.domain.factory.document.DefaultFactory;
import kevin.study.zephyr.domain.model.Document;
import kevin.study.zephyr.platform.Platform;

/**
 * @author Kevin.Huang
 * @date 2007-9-25
 */
public final class DocumentManager implements Observer {

	private DocumentFactory documentFactory = new DefaultFactory();;

	/**
	 * 针对Document的DAO
	 */
	private IGenericDAO<Document> documentDAO;

	private DocumentManager() {
		super();
	}

	static final class DocumentManagerHolder {
		private DocumentManagerHolder() {
		}

		static final DocumentManager SINGLETON = new DocumentManager();
	}

	/**
	 * 获取DocumentManager实例
	 *
	 * @return
	 */
	public static DocumentManager getDefault() {
		return DocumentManagerHolder.SINGLETON;
	}

	/**
	 * @param documentFactory
	 *            the documentFactory to set
	 */
	public void setDocumentFactory(DocumentFactory documentFactory) {
		this.documentFactory = documentFactory;
	}

	/**
	 * 取得documentDAO,用于操作Document
	 *
	 * @return the documentDAO
	 */
	public IGenericDAO<Document> getDocumentDAO() {
		if (documentDAO == null) {
			this.update(null, null);
		}
		return documentDAO;
	}

	public void update(Observable o, Object arg) {
		documentDAO = Platform.getDBManager().getDAO(Document.class);
	}

	/**
	 * @return the documentFactory
	 */
	public DocumentFactory getDocumentFactory() {
		return documentFactory;
	}

}
